Patch from Kristian Hogsberg Kristensen <hogsberg@daimi.au.dk> to avoid
authorFederico Mena Quintero <federico@redhat.com>
Fri, 22 Oct 1999 15:18:03 +0000 (15:18 +0000)
committerArturo Espinosa <unammx@src.gnome.org>
Fri, 22 Oct 1999 15:18:03 +0000 (15:18 +0000)
1999-10-22  Federico Mena Quintero  <federico@redhat.com>

* src/io-png.c (image_load): Patch from Kristian Hogsberg
Kristensen <hogsberg@daimi.au.dk> to avoid allocating extra row
buffers; the rows can be read in directly into the main pixel
buffer.

gdk-pixbuf/ChangeLog
gdk-pixbuf/io-png.c

index b9b56060b24ecc2d42b1366045936be448774cc6..205f992518f33be39c82a22b143fe438025b4012 100644 (file)
@@ -1,3 +1,10 @@
+1999-10-22  Federico Mena Quintero  <federico@redhat.com>
+
+       * src/io-png.c (image_load): Patch from Kristian Hogsberg
+       Kristensen <hogsberg@daimi.au.dk> to avoid allocating extra row
+       buffers; the rows can be read in directly into the main pixel
+       buffer.
+
 1999-10-20  Federico Mena Quintero  <federico@redhat.com>
 
        * src/gdk-pixbuf-io.c (image_handler_load): Free path.
index 733a505826b589abe75bf51abfb8c64d65afa12f..75a31f6f167818abbb875ea69f01276e31f42fac 100644 (file)
@@ -43,9 +43,9 @@ image_load (FILE *f)
        png_structp png_ptr;
        png_infop info_ptr, end_info;
        gint i, depth, ctype, inttype, passes, bpp;
-       png_uint_32 w, h, x, y;
+       png_uint_32 w, h;
        png_bytepp rows;
-       guchar *pixels, *temp, *rowdata;
+       guchar *pixels;
 
        png_ptr = png_create_read_struct (PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
        if (!png_ptr)
@@ -114,57 +114,19 @@ image_load (FILE *f)
                bpp = 3;
 
        pixels = malloc (w * h * bpp);
-       rows = malloc (h * sizeof (png_bytep));
-
-       if (!pixels || !rows) {
-               if (pixels)
-                       free (pixels);
-
-               if (rows)
-                       free (rows);
-
+       if (!pixels) {
                png_destroy_read_struct (&png_ptr, &info_ptr, &end_info);
                return NULL;
        }
 
-       /* Icky code, but it has to be done... */
-       for (i = 0; i < h; i++) {
-               if ((rows[i] = malloc (w * bpp)) == NULL) {
-                       int n;
+       rows = g_new (png_bytep, h);
 
-                       for (n = 0; n < i; n++)
-                               free (rows[i]);
+       for (i = 0; i < h; i++)
+               rows[i] = pixels + i * w * bpp;
 
-                       free (rows);
-                       free (pixels);
-                       png_destroy_read_struct (&png_ptr, &info_ptr, &end_info);
-                       return NULL;
-               }
-       }
-
-       /* And we FINALLY get here... */
        png_read_image (png_ptr, rows);
        png_destroy_read_struct (&png_ptr, &info_ptr, &end_info);
-
-       /* Now stuff the bytes into pixels & free rows[y] */
-
-       temp = pixels;
-
-       for (y = 0; y < h; y++) {
-               rowdata = rows[y];
-               for (x = 0; x < w; x++) {
-                       temp[0] = rowdata[(x * bpp)];
-                       temp[1] = rowdata[(x * bpp) + 1];
-                       temp[2] = rowdata[(x * bpp) + 2];
-
-                       if (bpp == 4)
-                               temp[3] = rowdata[(x * bpp) + 3];
-
-                       temp += bpp;
-               }
-               free (rows[y]);
-       }
-       free (rows);
+       g_free (rows);
 
        if (ctype & PNG_COLOR_MASK_ALPHA)
                return gdk_pixbuf_new_from_data (pixels, ART_PIX_RGB, TRUE,